package com.chenfan.mcn.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chenfan.mcn.extension.Res;
import com.chenfan.mcn.model.McnPage;
import com.chenfan.mcn.model.dto.DepartmentTargetDTO;
import com.chenfan.mcn.model.dto.DepartmentTargetSearchDTO;
import com.chenfan.mcn.model.vo.DepartmentTargetDetailVO;
import com.chenfan.mcn.model.vo.DepartmentTargetListVO;
import com.chenfan.mcn.model.vo.DepartmentTargetPageVO;
import com.chenfan.mcn.service.DepartmentTargetService;
import com.chenfan.privilege.common.config.SearchAuthority;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门目标
 * @author:   tangwei
 * Date:     2021/4/20 17:22
 * Description: 部门目标
 */
@RestController
@RequestMapping("/departmentTarget")
public class DepartmentTargetController {

    @Autowired
    private DepartmentTargetService departmentTargetService;

    /**
     * 新增
     * @param departmentTargetList
     * @return
     */
    @PostMapping("/add")
    public Res<Integer> addTarget(@RequestBody List<DepartmentTargetDTO> departmentTargetList) {
        return Res.ok(departmentTargetService.addTarget(departmentTargetList));
    }

    /**
     * 详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public Res<DepartmentTargetDTO> targetDetail(@RequestParam Long id) {
        return Res.ok(departmentTargetService.targetDetail(id));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("/delete")
    public Res<Integer> deleteTarget(@RequestParam Long id) {
        return Res.ok(departmentTargetService.deleteTarget(id));
    }

    /**
     * 编辑
     * @param departmentTargetDTO
     * @return
     */
    @PostMapping("/update")
    public Res<Integer> updateTarget(@RequestBody DepartmentTargetDTO departmentTargetDTO) {
        return Res.ok(departmentTargetService.updateTarget(departmentTargetDTO));
    }

    /**
     * 列表查询
     * @param dto
     * @return
     */
    @GetMapping("/list")
    public Res<List<DepartmentTargetListVO>> targetList(@SearchAuthority(filterCustomer = false) DepartmentTargetSearchDTO dto) {
        return Res.ok(departmentTargetService.targetList(dto));
    }

    /**
     * 分页列表查询
     * @param mcnPage
     * @param dto
     * @return
     */
    @GetMapping("/page")
    public Res<Page<DepartmentTargetPageVO>> targetPage(McnPage<DepartmentTargetPageVO> mcnPage, @SearchAuthority(filterCustomer = false) DepartmentTargetSearchDTO dto) {
        return Res.ok(departmentTargetService.targetPage(mcnPage, dto));
    }

    /**
     * 指定季度部门目标金额详情
     * @param quarterCode
     * @return
     */
    @GetMapping("/quarter/detail")
    public Res<List<DepartmentTargetDetailVO>> detailByQuarter(@RequestParam String quarterCode) {
        return Res.ok(departmentTargetService.detailByQuarter(quarterCode));
    }
}